package com.shop.bean;

import java.util.List;

public class Page<T> {
	private List<T> data;
	
	private int pageNum;
	
	private int pageSize;
	
	private int totalPages;
	
	private int totalRows;
	
	private boolean haveNext;
	
	private boolean havePrev;

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public boolean isHaveNext() {
		return haveNext;
	}

	public void setHaveNext(boolean haveNext) {
		this.haveNext = haveNext;
	}

	public boolean isHavePrev() {
		return havePrev;
	}

	public void setHavePrev(boolean havePrev) {
		this.havePrev = havePrev;
	}

	@Override
	public String toString() {
		return "Page [data=" + data + ", pageNum=" + pageNum + ", pageSize=" + pageSize + ", totalPages=" + totalPages
				+ ", totalRows=" + totalRows + ", haveNext=" + haveNext + ", havePrev=" + havePrev + "]";
	}

	public Page() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Page(List<T> data, int pageNum, int pageSize, int totalRows) {
		super();
		this.data = data;
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalRows = totalRows;
		this.totalPages = totalRows % pageSize == 0 ? (totalRows/pageSize) : (totalRows/pageSize) + 1;
		if(pageNum<=1) {
			this.havePrev = false;
		}else {
			this.havePrev = true;
		}
		if(pageNum>=totalPages) {
			this.haveNext = false;
		}else {
			this.haveNext = true;
		}
	}
	
	
	
}
